﻿using System;
using System.Collections.Generic;
using System.Windows;
using System.Text;
using System.Threading.Tasks;

namespace Molia.Premiere.Theme
{
    public enum ThemeType
    {
        Global = 1,
        Private = 2
    }
    public struct ThemeObject
    {
        public string Name { get; set; }
        public string Alias { get; set; }
        public ThemeType Level { get; set; }
        public string Runtime_Name { get; set; }
    }
    internal struct ThemeHost
    {
        public Window Wnd { get; set; }
        public string Name { get; set; }
    }

    public class ThemeManager
    {
        List<ThemeObject> _Res;//创建运行时资源与外部定义资源名的关联
        List<ThemeHost> _Wnd;
        Window _ref;

        public ThemeManager()
        {
            _Res = new List<ThemeObject>()
            {
                new ThemeObject()
                {
                    Runtime_Name="Theme.Foreground",
                    Alias ="Foreground",
                    Name="前景色"
                },
                new ThemeObject()
                {
                    Runtime_Name="Theme.Background",
                    Alias ="Background",
                    Name="背景"
                },
                new ThemeObject()
                {
                    Runtime_Name="Theme.MainFrame.MouseOver",
                    Alias ="MouseOver",
                    Name="按钮停放时的颜色"
                },
                new ThemeObject()
                {
                    Runtime_Name="Theme.MainFrame.Pressed",
                    Alias ="Pressed",
                    Name="按钮按下的颜色"
                },
                new ThemeObject()
                {
                    Runtime_Name="Theme.Button.Background",
                    Alias ="Button.Background",
                    Name="按钮背景1"
                },
                new ThemeObject()
                {
                    Runtime_Name="Theme.Theme.Combox.Border",
                    Alias ="Combox.Border",
                    Name="背景选择框边框"
                },
                new ThemeObject()
                {
                    Runtime_Name="Theme.Login.ID.MouseOver",
                    Alias ="MouseOver",
                    Name="登录框按钮按下颜色"
                }
            };
            _Wnd = new List<ThemeHost>();
        }

        public void Default(Window wnd)
        {
            _ref = wnd;
            if (_ref == null)
            {
                if (_Wnd.Count > 0)
                {
                    _ref = _Wnd[0].Wnd;
                }
                else
                {
                    throw new Exception("请指定默认窗体");
                }
            }
        }
        public void Registry(ThemeObject theme)
        {
            _Res.Add(theme);
        }
        public void Registry(Window wnd)
        {
            _Wnd.Add(new ThemeHost() { Wnd = wnd, Name = "" });
        }
        public void Registry(Window wnd, string name)
        {
            _Wnd.Add(new ThemeHost() { Wnd = wnd, Name = name });
        }
        public string Save()
        {
            //导出所有动态资源
            return "";
        }
        public object this[string name]
        {
            get
            {
                return _ref.Resources[name];
            }
            set
            {
                foreach (var i in _Wnd)
                {
                    i.Wnd.Resources[name] = value;
                }
            }
        }

    }
}
